package com.jan.client;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

public class SendHandle
    implements Runnable
{

  private Socket socket;
  private static LinkedBlockingQueue<DataPacket> msgQueue=new LinkedBlockingQueue<DataPacket>();
  public SendHandle(Socket socket){
    this.socket=socket;
  }
  public static void add(DataPacket packet){
    try
    {
      msgQueue.put(packet);
    }
    catch (InterruptedException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  @Override
  public void run()
  {

    OutputStream out;
    try
    {
      out = socket.getOutputStream();
      while(true){
        DataPacket packet=msgQueue.take();
        out.write(packet.toStringPacket().getBytes());
      }
    }
    catch (IOException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    catch (InterruptedException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   

  

  }

}
